package models

import (
	"gorm.io/gorm"
	"server/basic/config"
	"time"
)

type Order struct {
	Id          uint           `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	OrderSn     string         `gorm:"column:order_sn;type:varchar(255);comment:订单编号;not null;" json:"order_sn"` // 订单编号
	DocName     string         `gorm:"column:doc_name;type:varchar(255);not null;" json:"doc_name"`
	DocRoom     string         `gorm:"column:doc_room;type:varchar(255);not null;" json:"doc_room"`
	DocTitle    string         `gorm:"column:doc_title;type:varchar(255);not null;" json:"doc_title"`
	UserName    string         `gorm:"column:user_name;type:varchar(255);not null;" json:"user_name"`
	UserSymptom string         `gorm:"column:user_symptom;type:varchar(255);comment:患者症状;not null;" json:"user_symptom"` // 患者症状
	Times       time.Time      `gorm:"column:times;type:datetime(3);default:CURRENT_TIMESTAMP(3);" json:"times"`
	Price       uint           `gorm:"column:price;type:int UNSIGNED;comment:费用;not null;default:0;" json:"price"`                                                       // 费用
	OrderStatus uint           `gorm:"column:order_status;type:int UNSIGNED;comment:订单状态：1：已完结 2：已取消 3：待支付 4：已支付;not null;default:0;" json:"order_status"` // 订单状态：1：已完结 2：已取消 3：待支付 4：已支付
	CreatedAt   time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt   time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (o *Order) TableName() string {
	return "order"
}
func (o *Order) CreateOrder() error {
	return config.DB.Create(&o).Error
}
func (o *Order) UpdateOrder() error {
	return config.DB.Where("id = ?", o.Id).Updates(&o).Error
}
func (o *Order) GetOrderInfo() error {
	return config.DB.Where("id = ?", o.Id).Find(&o).Error
}
